package com.zrsx.searchmodel.controller;

import com.zrsx.searchmodel.common.dto.RecordDTO;
import com.zrsx.searchmodel.common.entity.Record;
import com.zrsx.searchmodel.common.result.PageResult;
import com.zrsx.searchmodel.common.result.Result;
import com.zrsx.searchmodel.service.RecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/record")
@Slf4j
@Tag(name = "守约记录")
public class RecordController {
    @Autowired
    private RecordService recordService;

    @GetMapping
    @Operation(summary = "获取守约记录（分页）")
    public Result<PageResult<Record>> getRecords(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "1") int pageSize,
            RecordDTO recordDTO
    ) {
        PageResult<Record> pageResult = recordService.getRecords(recordDTO, pageNum, pageSize);
        return Result.success(pageResult);
    }

    @GetMapping("/{userId}/{num}")
    @Operation(summary = "获取分数变化记录")
    public Result<List<Record>> getRecordsByNum(@PathVariable Integer userId, @PathVariable int num) {
        List<Record> records = recordService.getRecordsByNum(userId,num);
        return Result.success(records);
    }

    @GetMapping("/user/{userId}/{recordType}")
    @Operation(summary = "获取用户某类型守约记录数量")
    public Result<Integer> getRecordCountByType(@PathVariable Integer userId, @PathVariable String recordType) {
        int count = recordService.getRecordCountByType(userId, recordType);
        return Result.success(count);
    }
}
